package com.deli.springboot.service;

import com.deli.springboot.entity.BorrowHistory;
import com.deli.springboot.mapper.BorrowHistoryMapper;
import com.deli.springboot.repository.BorrowHistoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Service("borrowHistoryService")
public class BorrowHistoryServiceImpl implements BorrowHistoryService {

   /* @Autowired
    private BorrowHistoryRepository borrowHistoryRepository;*/
   @Autowired
   private BorrowHistoryMapper borrowHistoryMapper;

    @Override
    public Integer doAdd(BorrowHistory borrowHistory) {
        if (borrowHistory.getUserId() != 0 && borrowHistory.getUserId() != null) {

        }
        Date bDate = borrowHistory.getbDate();
        Calendar c = Calendar.getInstance();
        c.setTime(bDate);
        c.add(Calendar.DAY_OF_MONTH, 30);// 今天+30天

        Date rDate = c.getTime();
        borrowHistory.setrDate(rDate);
        borrowHistory.setStatus(1);

        try {
            Integer result = doAdd(borrowHistory);
            return result;
        } catch (Exception e) {

        }
        return null;
    }

    @Override
    public List<BorrowHistory> findByExample(BorrowHistory borrowHistory) {
        //return borrowHistoryRepository.findByExample(borrowHistory);
        return borrowHistoryMapper.findByExample(borrowHistory);
    }


    public Integer updateStatus(Long bookId) {
        //return borrowHistoryRepository.updateStatus(bookId);
        return borrowHistoryMapper.updateStatus(bookId);
    }
}
